package com.xiang.utils;


import android.content.Context;
import android.content.SharedPreferences;

public class sharedpreferencesUtil {
	Context context;

	public sharedpreferencesUtil(Context ctx) {
		context = ctx;
	}

	public void saveCity(String value) {
		put("city_info", "city", value);
		System.out.println("存city:" +value);
	}

	public void saveRegion(String value) {
		put("city_info", "region", value);
		System.out.println("存region:" +value);
	}

	public String getCity() {
		String city = get("city_info", "city");
		return city;
	}

	public String getRegion() {
		String region = get("city_info", "region");
		return region;
	}

	private void put(String preferencesName, String key, String value) {
		SharedPreferences userInfo = context.getSharedPreferences(
				preferencesName, 0);
		userInfo.edit().putString(key, value).commit();
	}

	private String get(String preferencesName, String key) {
		SharedPreferences userInfo = context.getSharedPreferences(
				preferencesName, 0);
		String username = userInfo.getString(key, "");
		return username;
	}
}
